<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								代理商名称：
									<input id="agentName" name="agentName"  />
									<input  type="hidden" id="agentNameList" value=""/><br>
							</li>
							<li>
								代理商编号：<input type="text" name="agentNo"/>
							</li>
							 <li>
								上级代理名称：
								<input id="parentId" name="parentId"/>
								<input type="hidden" id = "parentIdList" value=""/><br>
							</li>
							<li>
								代理商级别：<select name="tYPE" th:with="type=${@dict.getType('addAgent_type')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li>
								使 用 状 态：<select name="employStatus" th:with="type=${@dict.getType('agent_employStatus')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>

							<li>
								<a id="btnSearch" class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	       <!--  <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:hatchetAgent:add">
					<i class="fa fa-plus"></i> 添加
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="system:hatchetAgent:edit">
					<i class="fa fa-edit"></i> 修改
				</a>
				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:hatchetAgent:remove">
					<i class="fa fa-remove"></i> 删除
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:hatchetAgent:export">
						<i class="fa fa-download"></i> 导出
				 </a>
			</div> -->
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
	 <div id="dialog" class="modal fade text-center">
		  <div class="modal-dialog" style="display: inline-block; width:500px;">
		    <div class="modal-content">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		        <h4 class="modal-title">禁用原因</h4>
		      </div>
		      <div class="modal-body">
		       	<textarea id="remark"	rows="6" style="min-width: 90%"placeholder="请输入拒绝原因">
		       	</textarea>
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
		        <button onclick="doForbidden()" type="button" class="btn btn-primary">提交</button>
		      </div>
		    </div>
		  </div>
	</div>
	
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
       /*  var editFlag = [[${@permission.hasPermi('system:hatchetAgent:edit')}]];
       	var removeFlag = [[${@permission.hasPermi('system:hatchetAgent:remove')}]]; */
       	var listFlag = [[${@permission.hasPermi('system:hatchetMerchant:list')}]]; 
        var detailFlag = [[${@permission.hasPermi('system:hatchetAgent:detail')}]];
        var editFlag = [[${@permission.hasPermi('system:hatchetAgent:edit')}]];
        var types = [[${@dict.getType('agent_level')}]];
        var employStatus = [[${@dict.getType('agent_employStatus')}]];
        var prefix = ctx + "system/hatchetAgent";
    	var agentNameList = [];
        $(function() {
         	agents();
         	//代理商名称自动补全
         	$("#agentName").autocomplete({
        		source: agentNameList
        	});
         	$("#parentId").autocomplete({
        		source: agentNameList
        	});
         var options = {
                url: prefix + "/list",
             	/* removeUrl: prefix + "/remove", */
               	createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
             	detailUrl: prefix + "/detail/{id}",
				exportUrl: prefix + "/export",
				
                modalName: "代理商",
				search: false,
		        showExport: true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'agentName', 
					title : '代理商名称',
					sortable: true
				},
				{
					field : 'agentNo', 
					title : '代理商编号',
					sortable: true
				},
				{
					field : 'tYPE', 
					title : '代理商等级',
					align : 'left',
					formatter: function(value, item, index) {
						if(item.type=="3" && item.level=="1"){
							return "高级合伙人";
						}
			            return $.table.selectDictLabel(types, item.type);
			            }
				},
				{
					field : 'corpName', 
					title : '法人名称',
					sortable: true
				},
				{
					field : 'corpPhone', 
					title : '法人手机',
					sortable: true
				},
				{
					field : 'createTime', 
					title : '代理商创建时间',
					sortable: true
				},
				
				{
					field : 'parentId', 
					title : '上级代理商',
					sortable: true
				},
				{
					field : 'employStatus', 
					title : '使用状态',
					align: 'center',
					formatter: function(value, row, index) {
			            	return $.table.selectDictLabel(employStatus, value);
			            }
				},
				{
					field : 'logoText', 
					title : '冻结资金'
					
				},
				{
					field : 'fastCount', 
					title : '升级码数量',
					sortable: true
				},
				
				{
					field : 'totalMoney', 
					title : '账户总金额(元)',
					sortable: true
				} ,
				{
					field : 'uploadContract', 
					title : '余额状态',
					align: 'center',
		        	formatter: function (value, row, index) {
		        		return statusTools(row);
		        	}
				},
				{
					field : 'id', 
					title : 'ID',
					visible: true
				},
				
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	if (row.employStatus == "10A"){
		            	actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="#" onclick="$.operate.detail(\'' + row.id + '\')">代理商的详细</a> ');
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')">更新代理信息</a> ');
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="forbidden(\'' + row.id + '\')">禁用代理账号</a> ');
		            	actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="#" onclick="$.operate.add(\'' + row.id + '\')">新增下级代理</a> ');
		            	actions.push('<a class="btn btn-warning btn-xs"  href="#" onclick="checkMoney(\'' + row.id + '\')">清账对账</a> ');
		            	} else{
		            	actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="#" onclick="opens(\'' + row.id + '\')">开启</a> ');
		            	}
						return actions.join('');
		            }
		        }]
        }; 	
         $.table.init(options);
             	
   });
        var agentId ="";
        /* 代理状态-禁用 */
    	function forbidden(id) {
    		agentId = id;
    		$.modal.confirm("确认要禁用该代理？", function() {
    			$('#dialog').modal('show');//开启模态框 */
    		});
    	};
    	
    	 /* 代理状态-开启*/
    	function opens(agentId) {
    		$.modal.confirm("确认要开启该代理？", function() {
    			 $.ajax({
    					url : prefix + "/changeStatus",
    					type : "POST",
    					data: {
    						"agentId":agentId
    					},
    					success : function(re) {
    						if (re.status == "SUCCESS") {
    							$.modal.msgSuccess(re.msg);
    							$("#btnSearch").click();
    						} else {
    							$.modal.msgError(re.msg);
    						}
    					}
    				}); 
    		   })
    	};
    	
    	
    	 /* 清账对账*/
    	function checkMoney(id) {
    		$.modal.confirm("确认要核对清账？", function() {
    			 $.ajax({
    					url : prefix + "/checkMoney",
    					type : "POST",
    					data: {
    						"id":id
    					},
    					success : function(re) {
    						if (re.status == "SUCCESS") {
    							$.modal.msgSuccess(re.msg);
    						} else {
    							$.modal.msgError(re.msg);
    						}
    					}
    				}); 
    		   })
    	};
    	
    	/* 余额状态显示 */
		function statusTools(row) {
		    if (row.uploadContract=="1") {//冻结状态
    			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
    		} else {
    			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
    		}
		}
    	/* 余额账户冻结 */
		function disable(id) {
			$.modal.confirm("确认要冻结该代理商余额账户吗？", function() {
				$.operate.post(prefix + "/changeUploadContract", { "iD": id, "uploadContract": "1" });
		    })
		}

		/* 余额账户激活*/
		function enable(id) {
			$.modal.confirm("确认要激活该代理商余额账户吗？", function() {
				$.operate.post(prefix + "/changeUploadContract", { "iD": id, "uploadContract": "0" });
		    })
		}
    	
    	//查找所有代理商
 		function agents(){
    		var array=[];
			$.ajax({
				url: prefix + "/getAgentAll",
				async:false,
				type:"POST",
				data:{},
				success: function(result) {
					$.each(result, function(i,v) {
						if (v.agentName != null && v.agentName != undefined) {
							agentNameList.push(v.agentName);
							var arrays = {};
							arrays.value = v.agentName;
							arrays.id = v.id;
							array.push(arrays);
						}
					});
				}
			});
			return array;
    	} 
    	
    	function doForbidden(){
    		var logoText = $.trim($("#remark").val());
        	if(logoText.length==0){
        		$.modal.alertError("请输入禁用的原因");
        		return;
        	}
        	 $.ajax({
				url : prefix + "/changeStatus",
				type : "POST",
				data: {
					"agentId":agentId,
					"logoText":logoText  //
				},
				success : function(re) {
					if (re.status == "SUCCESS") {
						//关闭模态框
						$('#dialog').modal('hide');
						$.modal.msgSuccess(re.msg);
						$("#btnSearch").click();
					} else {
						$.modal.msgError(re.msg);
					}
				}
			}); 
    		
    		
    	}
    </script>
    
</body>
</html>